package org.example.io.bio;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BIOServerSocket {

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        try {
            serverSocket = new ServerSocket(8088);
            System.out.println("端口已启动");
            while(true){
                Socket socket = serverSocket.accept();
                System.out.println("一个客户端连接上了");
                executorService.submit(new SocketThread(socket));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if(serverSocket!=null){
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
